﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Comet_sample.Models
{
    /// <summary>
    /// Summary description for AsyncComet
    /// </summary>
    public class AsyncComet : IHttpAsyncHandler, IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            var cometAsyncResult = new CometAsyncResult(context, cb, extraData);
            var content = context.Request.Form["content"];
            Console.WriteLine(context);
            CometMessage.GetInstance().AddMessage(cometAsyncResult);
            return cometAsyncResult;
        }

        public void EndProcessRequest(IAsyncResult result)
        {
            //throw new NotImplementedException();
        }
    }
}